<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<style>
    .panel-primary > .bc {
        background-color: #008800;
    }
</style>
<script>
    //选中号表
    function selectReg(hed, preNum, limtNum) {
        if (limtNum != 0) {
            if (Number(preNum) >= Number(limtNum)) {
                toastr.warning("此号已经预约满");
                return false;
            }
        }
        if ($(hed).is(".bc")) {
            $(hed).removeClass("bc")
        } else {
            $(hed).addClass("bc");
        }
    }
    //保存预约信息
    function saveAppoints() {
        if (!$('#inputForm').parsley().validate()) {
            return false;
        }
        var clinic;
        $('#clinic header.bc input.simInput').each(function (index, element) {
            clinic = $(this).val();
        })
        if (clinic == null || clinic == 'undefined') {
            toastr.warning("请选择预约号");
            return false;
        }
        var idNO=$("#idNo").val();
        if(idNO!=null && idNO!=''){//根据身份证计算年龄
            var myDate = new Date();
            var month = myDate.getMonth() + 1;
            var day = myDate.getDate();
            var age = myDate.getFullYear() - idNO.substring(6, 10) - 1;
            if (idNO.substring(10, 12) < month || idNO.substring(10, 12) == month && idNO.substring(12, 14) <= day) {
                age++;
            }
            $("#age").val(age);
        }
        var regLen = $('#clinic header.bc');
        var labelHtml = "";
        var clinicIds = new Array();
        var totalPrice = 0;
        for (var i = 0; i < regLen.length; i++) {
            var clinicLabel = regLen.eq(i).find("#label").val();
            var price = regLen.eq(i).find("#price").val();
            var clinicId = regLen.eq(i).find("#clinicId").val();
            clinicIds.push(clinicId);
            labelHtml += '<a href="javascript:;" class="list-group-item">' +
                    '<span class="badge bg-primary pull-right">' + price + '</span>' +
                    '' + clinicLabel + '</a>';
        }
        /*labelHtml+=' <a href="javascript:;" class="list-group-item" style="color: red">'+
         '支付方式'+
         '<span class="pull-right">' +
         '<select name="payType" id="payType" class="form-control" data-parsley-required="true">'+

         '</select>'+
         '</span>'+
         '</a>';*/
        $("#reg").html(labelHtml);
        register = layer.open({
            title: '预约结果',
            type: 1,
            area: ['30%', '40%'],
            content: $("#regResult"),
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                ajaxData(clinicIds);
            }
        });
    }
    //保存数据
    function ajaxData(clinicIds) {
        if(flag){
             flag=false;
            $.ajax({
                type: 'post',
                url: '${ctx}/reg/clinicAppoints/save?clinicIds=' + clinicIds,
                data: $('#inputForm').serialize(),
                success: function (data) {
                    if (data.code == 'success') {
                        toastr.success(data.data);
                        layer.close(register);
                        loadDiv('mainCenterDiv', '${ctx}/reg/clinicAppoints/index');
                    }else{
                        flag=true;
                    }
                }
            });
        }

    }
</script>
<div class="app">
    <section class="layout">
        <aside class="col-lg-9 canvas-right bg-default pl0">
            <header class="header navbar clearfix bb bg-default pl10 pr0">
                <div class="pull-left">
                    <form:form id="searchForm" modelAttribute="regist"
                               onsubmit="return loadDivForm('mainCenterDiv','searchForm','${ctx}/reg/clinicAppoints/index');"
                               method="post" class="form-inline" style="padding-top: 10px;">
                        挂号日期:<input name="clinicDate" value="<fmt:formatDate value="${regist.clinicDate}"
                                                                        pattern="yyyy-MM-dd"/>" id="date" class="form-control Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,minDate:'%y-%M-{%d+1}'});"/>
                        门诊号别 ：<form:input path="clinicLabel" id="clinicName" class="form-control"/>
                        门诊科室 ：<form:input path="deptId" id="deptId" class="form-control"/>&nbsp;&nbsp;
                        <input id="search" class="btn btn-primary" type="submit" value="查询"/>&nbsp;&nbsp;
                    </form:form>
                </div>
            </header>
            <div class="content-wrap no-p">
                <div class="wrapper" style="bottom: 40px;">
                    <c:forEach items="${list}" var="clinicForReg">
                        <div class="col-md-4" id="clinic">
                            <section class="panel panel-primary no-b">
                                <header class="panel-heading clearfix brtl brtr"
                                        onclick="selectReg(this,'${clinicForReg.currentPreNum}','${clinicForReg.limitPreNum}')">
                                    <div class="overflow-hidden">
                                        <a href="javascript:;" class="h4 show no-m pt10 pull-left">${clinicForReg.clinicLabel}</a>
                                        <span class="badge pull-right bg-success">${clinicForReg.inputCode}</span>
                                        <input type="hidden" id="clinicId" class="simInput" value="${clinicForReg.id}">
                                        <input type="hidden" id="deptId" value="${clinicForReg.deptId}">
                                        <input type="hidden" id="doctor" value="${clinicForReg.doctorId}">
                                        <input type="hidden" id=label value="${clinicForReg.clinicLabel}">
                                        <input type="hidden" id="price" value="${clinicForReg.price}">
                                    </div>
                                </header>
                                <div class="list-group">
                                    <a href="javascript:;" class="list-group-item">
                                        <i class="ti-comment mr10 text-muted"></i>${fns:getDeptName(clinicForReg.deptId,'')}
                                    </a>
                                    <a href="javascript:;" class="list-group-item">
                                        <i class="ti-calendar mr10 text-muted"></i>${fns:getDictLabel(clinicForReg.timeDesc, 'TIME_OF_DAY', '')}
                                    </a>
                                    <a href="javascript:;" class="list-group-item">
                                        <i class="ti-bell mr10 text-muted"></i>${clinicForReg.currentPreNum}/${clinicForReg.limitPreNum}
                                    </a>
                                </div>
                            </section>
                        </div>
                    </c:forEach>
                    <div class="col-md-8 " id="regResult" style="display: none">
                        <section class="panel panel-primary no-b">
                            <div class="list-group" id="reg">

                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </aside>
        <!-- /mail sidebar navigation -->
        <!-- main content -->
        <section class="main-content" id="rigthCenterDiv">
            <div class="content-wrap">
                <div class="wrapper">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#">基本信息</a>
                        </li>
                    </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="col-lg-12">
                                <form id="inputForm" class="form-horizontal" data-parsley-validate="">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">姓名：</label>

                                        <div class="col-sm-8">
                                            <input name="name" id="name" class="form-control"
                                                   data-parsley-required="true" maxlength="8"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">性别：</label>

                                        <div class="col-sm-8">
                                            <select name="sex" class="form-control" data-parsley-required="true">
                                                <c:forEach items="${fns:getDictList('SEX_DICT')}" var="sex">
                                                    <option value="${sex.value}">${sex.label}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">年龄：</label>

                                        <div class="col-sm-8">
                                            <input name="age" class="form-control" id="age" type="number" max="100" min="0"
                                                   data-parsley-required="true" maxlength="3"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">费别：</label>

                                        <div class="col-sm-8">
                                            <%-- <input name="chargeType" class="form-control"  maxlength="100" />--%>
                                            <select name="chargeType" class="form-control">
                                                <c:forEach items="${fns:getDictList('CHARGE_TYPE_DICT')}"
                                                           var="chargeType">
                                                    <option value="${chargeType.value}">${chargeType.label}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">身份：</label>

                                        <div class="col-sm-8">
                                            <select name="identity" class="form-control">
                                                <c:forEach items="${fns:getDictList('PROFESSION_DICT')}"
                                                           var="profession">
                                                    <option value="${profession.value}">${profession.label}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">身份证号：</label>
                                        <div class="col-sm-8">
                                            <input name="idNo" class="form-control" data-parsley-required="true"
                                                   id="idNo" data-parsley-checkidcard="3"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">诊别：</label>
                                        <div class="col-sm-8">
                                            <select name="firstVisitIndicator" class="form-control">
                                                <c:forEach items="${fns:getDictList('first_visit_indicator')}"
                                                           var="firstVisit">
                                                    <option value="${firstVisit.value}">${firstVisit.label}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <%--<div class="form-group">--%>
                                        <%--<label class="col-sm-4 control-label">合同单位：</label>--%>

                                        <%--<div class="col-sm-8">--%>
                                            <%--<input name="unitInContract" class="form-control"/>--%>
                                        <%--</div>--%>
                                    <%--</div>--%>
                                </form>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"
                                               onclick="saveAppoints();">&nbsp;
                                        <input id="btnCancel" class="btn" type="button" value="取消">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
        <!-- /main content -->
    </section>
</div>